import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
import pytest
import openpyxl
import pymysql
import yaml


class ReadData:

    def read_excel(self,file_name='test.XLSX', sheet_name='user'):
        wb = openpyxl.load_workbook(file_name)
        sheet = wb[sheet_name]
        data = [[sheet.cell(row=i, column=j).value for j in range(1, sheet.max_column + 1)] for i in
                range(2, sheet.max_row + 1)]
        return data

    def read_sql(self):
        db = pymysql.connect(
            host='localhost',
            user='root',
            password='root',
            database='finance',
            port=3306,
            charset='utf8'
        )
        cursor = db.cursor()
        sql = 'select * from user'
        cursor.execute(sql)
        data = list(cursor.fetchall())
        return data

    def read_yaml(self):
        file = open('data.yaml', 'r', encoding='utf8')
        data = [file.read()]
        file.close()
        return data
